local mysql = {}
function mysql.selectRouterInfo(uuid)
    local mysql = require "resty.mysql"
    local cjson = require "cjson"
    local db, err = mysql:new()
    if not db then
    	ngx.log(ngx.ERR"failed to instantiate mysql: ", err)
        return
    end

    db:set_timeout(1000) -- 1 sec


    local ok, err, errcode, sqlstate = db:connect{
        host = "101.200.172.253",
        port = 3306,
        database = "cloudfiapi",
        user = "cloudfiapi",
        password = "cloudfipwd",
        charset = "utf8",
        max_packet_size = 1024 * 1024,
    }

    if not ok then
        ngx.log(ngx.ERR,"failed to connect: ", err, ": ", errcode, " ", sqlstate)
        return
    end

    local searchsql = "select * from t_api_deployinfo where uuid = " .. uuid
    local res, err, errcode, sqlstate =
        db:query(searchsql,1)
    --ngx.say(cjson.encode(res))
    if not res then
        ngx.log(ngx.ERR,"bad result: ", err, ": ", errcode, ": ", sqlstate, ".")
        return
    end
    local ok, err = db:set_keepalive(10000, 100)
    if not ok then
        ngx.log(ngx.ERR,"failed to set keepalive: ", err)
        return
    end
    return  res
end
function mysql.selectProxyInfo(ip)
    local mysql = require "resty.mysql"
    local cjson = require "cjson"
    local db, err = mysql:new()
    if not db then
        ngx.log(ngx.ERR"failed to instantiate mysql: ", err)
        return
    end

    db:set_timeout(1000) -- 1 sec


    local ok, err, errcode, sqlstate = db:connect{
        host = "101.200.172.253",
        port = 3306,
        database = "cloudfiapi",
        user = "cloudfiapi",
        password = "cloudfipwd",
        charset = "utf8",
        max_packet_size = 1024 * 1024,
    }

    if not ok then
        ngx.log(ngx.ERR,"failed to connect: ", err, ": ", errcode, " ", sqlstate)
        return
    end

    local searchsql = "select * from t_api_deployinfo where ip = '" .. ip .. "'"
    local res, err, errcode, sqlstate =
        db:query(searchsql,1)
    --ngx.say(cjson.encode(res))
    if not res then
        ngx.log(ngx.ERR,"bad result: ", err, ": ", errcode, ": ", sqlstate, ".")
        return
    end
    local ok, err = db:set_keepalive(10000, 100)
    if not ok then
        ngx.log(ngx.ERR,"failed to set keepalive: ", err)
        return
    end
    return  res
end
return mysql;
